﻿using System;
using Echo.Context.UltiProNet.Contexts;
using Echo.Core.Common;
using Echo.Core.TestAbstraction.WebUITest.MbUnit;
using Echo.Models.UltimateSoftware;
using Echo.Models.UltimateSoftware.WebUITest.MbUnit;
using MbUnit.Framework;

////*************************************************************************************************************************************
////Created by: Claudia De Leon
////Date created: 04/12/2013
////ULTI-94691 Location Business Rules - Add a Canada Location in .NET https://ultidev/browse/ULTI-94691
////*************************************************************************************************************************************

namespace Echo.Automation.Compliance.BusinessRules.Locations
{
    [TestFixture]
    [Author("Claudia De Leon", "claudia_deleon@ultimatesoftware.com")]
    [Category("Business Rules")]
    [Header("Config")]
    [Config(".NET")]
    public class AddCanadaLocation : MbUnitAutomatedTest
    {
        #region Setups / Teardowns
        UltiPro UltiPro;
        UltiProDatabaseContext Database;
        private readonly DateTime Date = DateTime.Today;

        [FixtureSetUp]
        public void FixtureSetUp()
        {
            #region Setup database ULTIPRO_CALENDAR
            UltiPro = Launch<UltiPro>();
            Database = Init<UltiProDatabaseContext>();
            Database.Company = ConfigDatabase("ULTIPRO_CALENDAR");
            Database.Company.AddRollBack("iLocation");
            Database.Company.AddRollBack("Loccomp");
            #endregion
        }

        [TearDown]
        public void TearDown()
        {
            UltiPro.Macros.Logout.Of_UltiPro();
        }

        [FixtureTearDown]
        public void FixtureTearDown()
        {
            Database.Company.RollBackDatabase();
            UltiPro.Browser.Quit();
        }
        #endregion

        [Test]
        [Timeout(2000)]
        public void AvailableFieldsOnAddChangeCanadaLocation()
        {
            #region GIVEN I select Canada as the location country
            AddANewCanadaLocation();
            #endregion
            
            #region WHEN The page loads
            UltiPro.Pages.AddChgLocations.Exists(header => header.ContactInformationHeader);
            UltiPro.Pages.AddChgLocations.Exists(header => header.TaxInformationHeader);
            #endregion
            
            #region THEN the Details section contains: Code, Description, Trade Name, Inactive checkbox, As of, GL segment, CMA code, Reporting category
            UltiPro.Pages.AddChgLocations.Is(header => header.DetailsHeader, "innerHTML", UltiPro.Localization.Strings.Details);
            UltiPro.Pages.AddChgLocations.Like(page => page.LocationCountryLabel, "innerHTML", UltiPro.Localization.Strings.Location.ToTitleCase());
            UltiPro.Pages.AddChgLocations.Like(page => page.LocationCountryLabel, "innerHTML", UltiPro.Localization.Strings.Country.ToLowerCase());
            UltiPro.Pages.AddChgLocations.Enabled(page => page.LocationCountryDropdown);
            UltiPro.Pages.AddChgLocations.Is(page => page.CodeLabel, "innerHTML", UltiPro.Localization.Strings.Code);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.CodeTextbox);
            UltiPro.Pages.AddChgLocations.Is(page => page.DescriptionTextbox.Description, "innerHTML", UltiPro.Localization.Strings.Description);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.DescriptionTextbox.EnglishTextBox);
            UltiPro.Pages.AddChgLocations.Is(page => page.TradeNameTextbox.Description, "innerHTML", UltiPro.Localization.Strings.Trade_name);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.TradeNameTextbox.EnglishTextBox);
            UltiPro.Pages.AddChgLocations.Is(page => page.InactiveLabel, "innerHTML", UltiPro.Localization.Strings.Inactive);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.InactiveCheckbox);
            UltiPro.Pages.AddChgLocations.Is(page => page.AsOfLabel, "innerHTML", UltiPro.Localization.Strings.As_of.ToLowerCase());
            UltiPro.Pages.AddChgLocations.InactiveDate.Exists();
            UltiPro.Pages.AddChgLocations.Is(page => page.GlSegmentLabel, "innerHTML", UltiPro.Localization.Strings.GL_segment);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.GlSegmentTextbox);
            UltiPro.Pages.AddChgLocations.Is(page => page.CmaCodeLabel, "innerHTML", "CMA Code");
            UltiPro.Pages.AddChgLocations.Enabled(page => page.CmaDropdown);
            UltiPro.Pages.AddChgLocations.Is(page => page.ReportingCategoryLabel, "innerHTML", UltiPro.Localization.Strings.Reporting_category);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.ReportingCategoryDropdown);
            #endregion
            
            #region AND the Physical Address section contains: Location country, Address 1, Address 2, City, State, Province, Postal code
            UltiPro.Pages.AddChgLocations.Is(page => page.PhysicalAddressHeader, "innerHTML", "Physical Address");
            // Location country
            UltiPro.Pages.AddChgLocations.Is(page => page.LocationCountryLabel, "innerHTML", "Location country");
            UltiPro.Pages.AddChgLocations.Is(page => page.LocationCountryValue, "innerHTML", "Canada");
            // Address 1
            UltiPro.Pages.AddChgLocations.Is(page => page.PhyicalAddressLine1Label, "innerHTML", "Address 1");
            UltiPro.Pages.AddChgLocations.Exists(page => page.PhyicalAddressLine1Texbox);
            // Address 2
            UltiPro.Pages.AddChgLocations.Is(page => page.PhyicalAddressLine2Label, "innerHTML", "Address 2");
            UltiPro.Pages.AddChgLocations.Exists(page => page.PhyicalAddressLine2Texbox);
            // City
            UltiPro.Pages.AddChgLocations.Is(page => page.PhyicalAddressCityLabel, "innerHTML", "City");
            UltiPro.Pages.AddChgLocations.Exists(page => page.PhyicalAddressCityTexbox);
            // Province
            UltiPro.Pages.AddChgLocations.Is(page => page.PhyicalAddressStateProvinceLabel, "innerHTML", "Province");
            UltiPro.Pages.AddChgLocations.Exists(page => page.PhyicalAddressStateProvinceDropdown);
            // Postal Code
            UltiPro.Pages.AddChgLocations.Is(page => page.PhyicalAddressZipPostalCodeLabel, "innerHTML", "Postal code");
            UltiPro.Pages.AddChgLocations.Exists(page => page.PhyicalAddressZipPostalCodeTexbox);
            #endregion
            
            #region AND the Contact Information section contains: Contact country, Address 1, Address 2, City, Province, Postal Code, County, Contact name, Mailstop, Delivery barcode, Phone number, Extension, Fax number, Modem number
            UltiPro.Pages.AddChgLocations.Is(header => header.ContactInformationHeader, "innerHTML", UltiPro.Localization.Strings.Contact_Information);
            // Contact country
            UltiPro.Pages.AddChgLocations.Like(page => page.ContactCountryLabel, "innerHTML", UltiPro.Localization.Strings.Contact_Country.ToSentenceCase());
            UltiPro.Pages.AddChgLocations.Enabled(page => page.ContactCountryDropdown);
            // Address 1
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactAddressLine1Label, "innerHTML", UltiPro.Localization.Strings.Address_1);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.ContactAddressLine1Texbox);
            // Address 2
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactAddressLine2Label, "innerHTML", UltiPro.Localization.Strings.Address_2);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.ContactAddressLine2Texbox);
            // City
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactCityLabel, "innerHTML", UltiPro.Localization.Strings.City);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.ContactCityTexbox);
            // Province
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactStateProvinceLabel, "innerHTML", UltiPro.Localization.Strings.Province);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.ContactStateProvinceDropdown);
            // Postal Code
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactZipPostalCodeLabel, "innerHTML", "Postal code");
            UltiPro.Pages.AddChgLocations.Enabled(page => page.ContactZipPostalCodeTexbox);
            // County
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactCountyLabel, "innerHTML", UltiPro.Localization.Strings.County);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.ContactCountyTexbox);
            // Contact name
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactNameLabel, "innerHTML", UltiPro.Localization.Strings.Contact_name);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.ContactNameTexbox);
            // Mailstop
            UltiPro.Pages.AddChgLocations.Is(page => page.MailstopLabel, "innerHTML", UltiPro.Localization.Strings.Mailstop);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.MailstopTexbox);
            // Delivery barcode
            UltiPro.Pages.AddChgLocations.Is(page => page.DeliveryBarCodeLabel, "innerHTML", UltiPro.Localization.Strings.Delivery_bar_code);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.DeliveryBarCodeTextbox);
            // Phone number
            UltiPro.Pages.AddChgLocations.Like(page => page.PhoneNumberLabel, "innerHTML", UltiPro.Localization.Strings.Phone);
            UltiPro.Pages.AddChgLocations.Like(page => page.PhoneNumberLabel, "innerHTML", UltiPro.Localization.Strings.Number.ToLowerCase());
            UltiPro.Pages.AddChgLocations.Enabled(page => page.PhoneNumberTextbox);
            // Extension 
            UltiPro.Pages.AddChgLocations.Is(page => page.ExtensionLabel, "innerHTML", UltiPro.Localization.Strings.Extension);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.ExtensionTextbox);
            // Fax number
            UltiPro.Pages.AddChgLocations.Is(page => page.FaxNumberLabel, "innerHTML", UltiPro.Localization.Strings.Fax_number);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.FaxNumberTextbox);
            // Modem number
            UltiPro.Pages.AddChgLocations.Is(page => page.ModemNumberLabel, "innerHTML", UltiPro.Localization.Strings.Modem_number);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.ModemNumberTextbox);
            #endregion
            
            #region AND the Tax Information section contains: Provincial Territory taxes header, Province/Territory, Companies using this tax location header, Find by filter, Companies mover box
            UltiPro.Pages.AddChgLocations.Is(header => header.TaxInformationHeader, "innerHTML", UltiPro.Localization.Strings.Tax_Information);
            UltiPro.Pages.AddChgLocations.Is(header => header.ProvincialTerritorialTaxesLegend, "innerHTML", UltiPro.Localization.Strings.Provincial_slash_Territorial_taxes);
            UltiPro.Pages.AddChgLocations.Like(page => page.ProvinceTerritoryLabel, "innerHTML", UltiPro.Localization.Strings.Province_slash_Territory);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.ProvinceTerritoryDropdown);
            UltiPro.Pages.AddChgLocations.Is(header => header.CompaniesUsingThisTaxLocationLegend, "innerHTML", UltiPro.Localization.Strings.Companies_using_this_tax_location);
            UltiPro.Pages.AddChgLocations.CompaniesOptionMover.Exists(box => box.Source);
            UltiPro.Pages.AddChgLocations.CompaniesOptionMover.Exists(box => box.Destination);
            UltiPro.Pages.AddChgLocations.ButtonBar.Click(button => button.Cancel);
            UltiPro.Alert.Accept();
            #endregion
        }

        [Test]
        public void RequiredFieldsOnAddChangeLocation()
        {
            #region GIVEN I select Canada as the location country
            AddANewCanadaLocation();
            #endregion
            
            #region WHEN I attempt to save the page
            UltiPro.Pages.AddChgLocations.ButtonBar.Click(button => button.Save);
            #endregion
            
            #region THEN I get an error message:"Please correct the 5 highlighted field(s) before continuing"
            UltiPro.Pages.AddChgLocations.ErrorMessages.Has("Please correct the 10 highlighted field(s) before continuing");
            UltiPro.Pages.AddChgLocations.ButtonBar.Click(button => button.Cancel);
            UltiPro.Alert.Accept();
            #endregion
        }

        [Test]
        [Row("NT Prov Tax")]
        [Row("NU Prov Tax")]
        public void OtherTaxCodeFieldOnAddChangeLocation(string stateTax)
        {
            #region GIVEN I select Canada as the location country
            AddANewCanadaLocation();
            #endregion
            
            #region WHEN I select NU/NT Prov Tax on the Province/Territory dropdown for Tax Information
            UltiPro.Pages.AddChgLocations.Set(page => page.ProvinceTerritoryDropdown, stateTax, SelectOption.Text);
            #endregion
            
            #region THEN the Provincial/Territorial taxes section displays Other tax code as a required field
            UltiPro.Pages.AddChgLocations.Like(page => page.OtherTaxCodeLabel, "innerHTML", UltiPro.Localization.Strings.Other);
            UltiPro.Pages.AddChgLocations.Like(page => page.OtherTaxCodeLabel, "innerHTML", UltiPro.Localization.Strings.Tax_code.ToLowerCase());
            UltiPro.Pages.AddChgLocations.Enabled(page => page.OtherTaxCodeDropdown);
            UltiPro.Pages.AddChgLocations.ButtonBar.Click(button => button.Cancel);
            UltiPro.Alert.Accept();
            #endregion
        }

        [Test]
        public void AdditionalFieldsForQuebecProvincialTaxes()
        {
            #region GIVEN I select Canada as the location country
            AddANewCanadaLocation();
            #endregion
            
            #region WHEN I select QC Prov Tax on the Province/Territory dropdown for Tax Information
            UltiPro.Pages.AddChgLocations.Set(page => page.ProvinceTerritoryDropdown, "QC Prov Tax", SelectOption.Text);
            #endregion
            
            #region THEN the Provincial/Territorial taxes section displays Other tax code and QEID
            UltiPro.Pages.AddChgLocations.Like(page => page.OtherTaxCodeLabel, "innerHTML", UltiPro.Localization.Strings.Other);
            UltiPro.Pages.AddChgLocations.Like(page => page.OtherTaxCodeLabel, "innerHTML", UltiPro.Localization.Strings.Tax_code.ToLowerCase());
            UltiPro.Pages.AddChgLocations.Enabled(page => page.OtherTaxCodeDropdown);
            UltiPro.Pages.AddChgLocations.Is(page => page.QuebecEmployerIdLabel, "innerHTML", UltiPro.Localization.Strings.Quebec_employer_identification);
            UltiPro.Pages.AddChgLocations.Enabled(page => page.QuebecEmployerIdDropdown);
            UltiPro.Pages.AddChgLocations.ButtonBar.Click(button => button.Cancel);
            UltiPro.Alert.Accept();
            #endregion
        }

        [Test]
        public void SpecialCharactersOnEditableFields()
        {
            #region GIVEN I select Canada as the location country and complete the required fields
            AddANewCanadaLocation();
            CompleteRequiredFieldsForDetails("CNDAB", "CNDAlberta", "85 - Alberta less CMAs");
            CompleteRequiredFieldsForPhysicalAddress("6745 Ponce Lane", "Marcela", "Ontario", "A2A2A2");
            UltiPro.Pages.AddChgLocations.Set(page => page.ProvinceTerritoryDropdown, "AB Prov Tax", SelectOption.Text);
            UltiPro.Pages.AddChgLocations.Set(x => x.CompaniesOptionMover.Source, "HCCO1-CalenHR - CN Comp 1", SelectOption.Text);
            UltiPro.Pages.AddChgLocations.Click(button => button.CompaniesOptionMover.ArrowRight);
            #endregion
            
            #region WHEN I enter: Special characters (%^&%*()_(*&^%$#), letters and numbers on County, Delivery bar code and Contact name
            UltiPro.Pages.AddChgLocations.Set(page => page.ContactCountyTexbox, "&^*%$%%&^*");
            UltiPro.Pages.AddChgLocations.Set(page => page.DeliveryBarCodeTextbox, "54");
            UltiPro.Pages.AddChgLocations.Set(page => page.ContactNameTexbox, "-87677#c^&*+");
            #endregion
            
            #region AND attempt to save
            UltiPro.Pages.AddChgLocations.ButtonBar.Click(button => button.Save);
            #endregion
            
            #region THEN the pages saves the special characters on the fields
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactCountyValue, "innerHTML", "&^*%$%%&^*");
            UltiPro.Pages.AddChgLocations.Is(page => page.DeliveryBarCodeValue, "innerHTML", "54");
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactNameValue, "innerHTML", "-87677#c^&*+");
            UltiPro.Pages.AddChgLocations.ButtonBar.Click(button => button.Back);
            #endregion

            #region Database check
            /*Database.Company.Verify("SELECT loccode, LocAddressCounty, LocBarCode, LocContact FROM location WHERE loccode = 'CNDAL' AND LocAddressCounty = '&^*%$%%&^*' " +
                                     "AND LocBarCode = '54' AND LocContact = '-87677#c^&*+'", "LocationBusinessRules/LOC_SpecialCharOnEditFields.xml");
            Database.Company.Verify("SELECT CmpCompanyName, CmpCoID FROM Loccomp JOIN Company on CmpCoID = lcpcoid WHERE lcpCode = 'CNDAL' ORDER BY lcpcode", "LocationBusinessRules/LOCCMP_SpecialCharOnEditFields.xml");*/
            #endregion
        }

        [Test]
        public void QuebecEmployerIdentificationNumberDropdownValues()
        {
            #region GIVEN I select Canada as the location country and Quebec as the Provincial Tax
            AddANewCanadaLocation();
            UltiPro.Pages.AddChgLocations.Set(page => page.CodeTextbox, "CNDQC");
            UltiPro.Pages.AddChgLocations.Set(page => page.DescriptionTextbox.EnglishTextBox, "CNDQuebec");
            UltiPro.Pages.AddChgLocations.Set(page => page.CmaDropdown, "54 - Québec", SelectOption.Text);
            UltiPro.Pages.AddChgLocations.Set(page => page.ProvinceTerritoryDropdown, "QC Prov Tax", SelectOption.Text);
            #endregion

            #region WHEN I set The First Canadian Company from the Companies using this tax location dropdown
            UltiPro.Pages.AddChgLocations.Set(page => page.CompaniesOptionMover.Source, "The First Canadian Company", SelectOption.Text);
            UltiPro.Pages.AddChgLocations.Click(button => button.CompaniesOptionMover.ArrowRight);
            #endregion
            
            #region THEN the Quebec employer identification dropdown gets populated with values: Establishment2, Establishment3, Executive
            UltiPro.Pages.AddChgLocations.HasOption(page => page.QuebecEmployerIdDropdown, "QCL2", SelectOption.Value);
            UltiPro.Pages.AddChgLocations.HasOption(page => page.QuebecEmployerIdDropdown, "QCL3", SelectOption.Value);
            UltiPro.Pages.AddChgLocations.HasOption(page => page.QuebecEmployerIdDropdown, "0", SelectOption.Value);
            UltiPro.Pages.AddChgLocations.ButtonBar.Click(button => button.Cancel);
            UltiPro.Alert.Accept();
            #endregion
        }

        [Test]
        public void CompanyNotSetupForTaxCode()
        {
            #region GIVEN I select Canada as the location and complete required fields Code, Description, CMA Code, Physical Address (...)
            AddANewCanadaLocation();
            CompleteRequiredFieldsForDetails("CNDNB", "CNDNB", "88 - New Brunswick less CMA");
            CompleteRequiredFieldsForPhysicalAddress("6745 Angel St", "City in Alberta", "Alberta", "A2A 2A2");
            #endregion
            
            #region WHEN I select NB Prov Tax as the Work in State and TALENT as the company and Save the page
            UltiPro.Pages.AddChgLocations.Set(page => page.WorkInStateDropdown, "NB Prov Tax", SelectOption.Text);
            UltiPro.Pages.AddChgLocations.Set(page => page.CompaniesOptionMover.Source, "TALENT", SelectOption.Text);
            UltiPro.Pages.AddChgLocations.Click(button => button.CompaniesOptionMover.ArrowRight);
            UltiPro.Pages.AddChgLocations.ButtonBar.Click(button => button.Save);
            #endregion
            
            #region THEN I get an error message: Tax code "NBPIT" not setup for "TALENT".
            UltiPro.Pages.AddChgLocations.ErrorMessages.Has("Tax code \"NBPIT\" not setup for \"TALENT\".");
            UltiPro.Pages.AddChgLocations.ButtonBar.Click(button => button.Cancel);
            UltiPro.Alert.Accept();
            #endregion
        }

        [Test]
        public void SaveLocationWithAllFields()
        {
            #region GIVEN I select Canada as the location country and complete ALL the fields on the page
            // Details
            AddANewCanadaLocation();
            CompleteRequiredFieldsForDetails("CND", "CNDAB", "85 - Alberta less CMAs");
            //Non-required fields
            UltiPro.Pages.AddChgLocations.Click(page => page.InactiveCheckbox);
            UltiPro.Pages.AddChgLocations.InactiveDate.Set(Date);
            UltiPro.Pages.AddChgLocations.Set(page => page.ReportingCategoryDropdown, "CAN Rep Cat", SelectOption.Text);
            CompleteRequiredFieldsForPhysicalAddress("6745 Ponce Lane", "Marcela", "Ontario", "A2A 2A2");
            // Contact Information
            UltiPro.Pages.AddChgLocations.Set(page => page.ContactCountryDropdown, "Mexico", SelectOption.Text);
            UltiPro.Pages.AddChgLocations.Set(page => page.ContactAddressLine1Texbox, "6745 Ponce Lane");
            UltiPro.Pages.AddChgLocations.Set(page => page.ContactAddressLine2Texbox, "6746 Ponce Terr");
            UltiPro.Pages.AddChgLocations.Set(page => page.ContactCityTexbox, "Marcela");
            UltiPro.Pages.AddChgLocations.Set(page => page.ContactStateProvinceDropdown, "Oaxaca ENG", SelectOption.Text);
            UltiPro.Pages.AddChgLocations.Set(page => page.ContactZipPostalCodeTexbox, "26571");
            UltiPro.Pages.AddChgLocations.Set(page => page.ContactCountyTexbox, "ALBERTA");
            UltiPro.Pages.AddChgLocations.Set(page => page.ContactNameTexbox, "Rose Ann");
            UltiPro.Pages.AddChgLocations.Set(page => page.MailstopTexbox, "Lorem");
            UltiPro.Pages.AddChgLocations.Set(page => page.DeliveryBarCodeTextbox, "CN");
            UltiPro.Pages.AddChgLocations.Set(page => page.PhoneNumberTextbox, "(786)258-3382");
            UltiPro.Pages.AddChgLocations.Set(page => page.ExtensionTextbox, "+25");
            UltiPro.Pages.AddChgLocations.Set(page => page.FaxNumberTextbox, "(786)258-3382");
            UltiPro.Pages.AddChgLocations.Set(page => page.ModemNumberTextbox, "(786)258-3382");
            UltiPro.Pages.AddChgLocations.Set(page => page.CompaniesOptionMover.Source, "The Second Canadian Company", SelectOption.Text);
            UltiPro.Pages.AddChgLocations.Click(button => button.CompaniesOptionMover.ArrowRight);
            UltiPro.Pages.AddChgLocations.Set(page => page.ProvinceTerritoryDropdown, "AB Prov Tax", SelectOption.Text);
            #endregion

            #region WHEN I click the Save button
            UltiPro.Pages.AddChgLocations.ButtonBar.Click(button => button.Save);
            #endregion
            
            #region THEN the page is displayed in View mode
            UltiPro.Pages.AddChgLocations.ButtonBar.Exists(button => button.Edit);
            UltiPro.Pages.AddChgLocations.ButtonBar.Exists(button => button.Back);
            UltiPro.Pages.AddChgLocations.ButtonBar.Exists(button => button.Delete);
            #endregion
            
            #region AND all the fields hold their values
            // Details
            UltiPro.Pages.AddChgLocations.Is(page => page.LocationCountryValue, "innerHTML", "Canada");
            UltiPro.Pages.AddChgLocations.Is(page => page.CodeValue, "innerHTML", "CND");
            UltiPro.Pages.AddChgLocations.Is(page => page.DescriptionValueEn, "innerHTML", "CNDAB");
            UltiPro.Pages.AddChgLocations.Is(page => page.TradeNameValueEn, "innerHTML", "CNDAB");
            UltiPro.Pages.AddChgLocations.Is(page => page.GlSegmentValue, "innerHTML", "CND");
            UltiPro.Pages.AddChgLocations.Selected(page => page.InactiveCheckbox);
            UltiPro.Pages.AddChgLocations.Is(page => page.InactiveDateValue, "innerHTML", Date.ToString("MM/dd/yyyy"));
            UltiPro.Pages.AddChgLocations.Is(page => page.CmaValue, "innerHTML", "85 - Alberta less CMAs");
            UltiPro.Pages.AddChgLocations.Is(page => page.ReportingCategoryValue, "innerHTML", "LOCCAN - CAN Rep Cat");
            // Physical Address
            UltiPro.Pages.AddChgLocations.Is(page => page.PhyicalAddressCountryValue, "innerHTML", "Canada");
            UltiPro.Pages.AddChgLocations.Is(page => page.PhyicalAddressLine1Value, "innerHTML", "6745 Ponce Lane");
            UltiPro.Pages.AddChgLocations.Is(page => page.PhyicalAddressLine2Value, "innerHTML", "APT. 326");
            UltiPro.Pages.AddChgLocations.Is(page => page.PhyicalAddressCityValue, "innerHTML", "Marcela");
            UltiPro.Pages.AddChgLocations.Is(page => page.PhyicalAddressStateProvinceValue, "innerHTML", "Ontario");
            UltiPro.Pages.AddChgLocations.Is(page => page.PhyicalAddressZipPostalCodeValue, "innerHTML", "A2A 2A2");
            // Contact information
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactCountryValue, "innerHTML", "Mexico");
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactAddressLine1Value, "innerHTML", "6745 Ponce Lane");
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactAddressLine2Value, "innerHTML", "6746 Ponce Terr");
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactCityValue, "innerHTML", "Marcela");
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactStateProvinceValue, "innerHTML", "Oaxaca ENG");
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactZipPostalCodeValue, "innerHTML", "26571");
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactCountyValue, "innerHTML", "ALBERTA");
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactNameValue, "innerHTML", "Rose Ann");
            UltiPro.Pages.AddChgLocations.Is(page => page.MailstopValue, "innerHTML", "Lorem");
            UltiPro.Pages.AddChgLocations.Is(page => page.DeliveryBarCodeValue, "innerHTML", "CN");
            UltiPro.Pages.AddChgLocations.Is(page => page.PhoneNumberValue, "innerHTML", "7862583382");
            UltiPro.Pages.AddChgLocations.Is(page => page.ExtensionValue, "innerHTML", "+25");
            UltiPro.Pages.AddChgLocations.Is(page => page.FaxNumberValue, "innerHTML", "7862583382");
            UltiPro.Pages.AddChgLocations.Is(page => page.ModemNumberValue, "innerHTML", "7862583382");
            // Tax Information
            UltiPro.Pages.AddChgLocations.Is(page => page.WorkInStateValue, "innerHTML", "AB Prov Tax");
            UltiPro.Pages.AddChgLocations.Is(page => page.CompaniesUsingThisTaxLocationList(1), "innerHTML", "The Second Canadian Company");
            UltiPro.Pages.AddChgLocations.ButtonBar.Click(button => button.Back);
            #endregion
        }

        // https://ultidev/browse/ULTI-106377
        [Test]
        public void TaxCodeSectionHiddenForGlobalCanada()
        {
            #region GIVEN that I remove the product key for a Canadian Company in CALEN
            Database.Company.Execute("DELETE FROM productkeys WHERE prkprodcode = 'CAN'");
            Database.Company.Execute("DELETE FROM rbsproductkeys WHERE prkprodcode = 'can'");
            TestSupport.Service.ServiceHelper.ResetIIS("devtxweb01");
            AddANewCanadaLocation();
            #endregion

            #region WHEN I add a new Canadian location
            UltiPro.Macros.Navigate.ToBusinessRule("Locations");
            UltiPro.Pages.LocationSummary.ButtonBar.Click(button => button.Add);
            UltiPro.Pages.AddChgLocations.Set(page => page.LocationCountryDropdown, "Canada", SelectOption.Text);
            #endregion

            #region THEN the Tax Information section is not present on the Add Location page
            UltiPro.Pages.AddChgLocations.NotExists(page => page.TaxInformationHeader);
            UltiPro.Pages.AddChgLocations.NotExists(page => page.ProvincialTerritorialTaxesLegend);
            UltiPro.Pages.AddChgLocations.NotExists(page => page.ProvinceTerritoryLabel);
            UltiPro.Pages.AddChgLocations.NotExists(page => page.ProvinceTerritoryDropdown);
            #endregion

            #region Restore Product Key
            Database.Company.Execute("INSERT INTO productkeys VALUES ('CAN', 0xDD6B1A787546D611000000000000000000000000)");
            Database.Company.Execute("SET IDENTITY_INSERT rbsproductkeys ON INSERT INTO rbsproductkeys(PRKPRODKEY, PRKID, PRKPRODCODE)" +
                                     " VALUES ('agMcNUbzmtsfnJ3d2guH1g==', 2, 'CAN') SET IDENTITY_INSERT rbsproductkeys OFF");
            TestSupport.Service.ServiceHelper.ResetIIS("devtxweb01");
            #endregion
        }

        //https://ultidev/browse/ULTI-106036
        [Test]
        public void ContactInformationLabels()
        {
            #region GIVEN that I add a new Canada location
            AddANewCanadaLocation();
            #endregion

            #region WHEN I select a Contact country (US, Canada, Global)
            #endregion

            #region THEN the Contact Information labels vay depending on the country selection 
            #region CANADA: Address line 1, Address line 2, Province, Postal code
            UltiPro.Pages.AddChgLocations.Set(page => page.ContactCountryDropdown, "Canada", SelectOption.Text);
            UltiPro.Pages.AddChgLocations.Exists(page => page.ContactAddressLine1Label);
            UltiPro.Pages.AddChgLocations.Exists(page => page.ContactAddressLine2Label);
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactStateProvinceLabel, "innerHTML", "Province");
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactZipPostalCodeLabel, "innerHTML", "Postal code");
            #endregion
            
            #region UNITED STATES: Address line 1, Address line 2, State, Zip/Postal code
            UltiPro.Pages.AddChgLocations.Set(page => page.ContactCountryDropdown, "United States", SelectOption.Text);
            UltiPro.Pages.AddChgLocations.Exists(page => page.ContactAddressLine1Label);
            UltiPro.Pages.AddChgLocations.Exists(page => page.ContactAddressLine2Label);
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactStateProvinceLabel, "innerHTML", "State");
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactZipPostalCodeLabel, "innerHTML", "Zip/Postal code");
            #endregion

            #region MEXICO: Address line 1, Address line 2, Address line 3, Address line 4, State/Province, Postal code
            UltiPro.Pages.AddChgLocations.Set(page => page.ContactCountryDropdown, "Mexico", SelectOption.Text);
            UltiPro.Pages.AddChgLocations.Exists(page => page.ContactAddressLine1Label);
            UltiPro.Pages.AddChgLocations.Exists(page => page.ContactAddressLine2Label);
            UltiPro.Pages.AddChgLocations.Exists(page => page.ContactAddressLine3Label);
            UltiPro.Pages.AddChgLocations.Exists(page => page.ContactAddressLine4Label);
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactStateProvinceLabel, "innerHTML", "State/Province");
            UltiPro.Pages.AddChgLocations.Is(page => page.ContactZipPostalCodeLabel, "innerHTML", "Postal code");
            #endregion
            #endregion
        }

        #region HELPERS
        /// <summary>
        /// Complete all required fields on the Details section for a new Canada location
        /// </summary>
        /// <param name="code">Location code</param>
        /// <param name="description">Location Description same as Trade name</param>
        /// <param name="cmaCode">CMA code</param>
        public void CompleteRequiredFieldsForDetails(string code, string description, string cmaCode)
        {
            UltiPro.Pages.AddChgLocations.Set(page => page.CodeTextbox, code);
            UltiPro.Pages.AddChgLocations.Set(page => page.DescriptionTextbox.EnglishTextBox, description);
            UltiPro.Pages.AddChgLocations.Set(page => page.TradeNameTextbox.EnglishTextBox, description);
            UltiPro.Pages.AddChgLocations.Set(page => page.CmaDropdown, cmaCode, SelectOption.Text);
        }

        /// <summary>
        /// Complete all required fields on the Physical Address section for a new Canada location
        /// </summary>
        /// <param name="addLine1">Addres line 1</param>
        /// <param name="city">Physical Address City</param>
        /// <param name="province">Physical Address Province</param>
        /// <param name="zipPostalCode">Physical Address Postal code</param>
        public void CompleteRequiredFieldsForPhysicalAddress(string addLine1, string city, string province, string zipPostalCode)
        {
            // Added required Physical Address fields: https://ultidev/browse/ULTI-106367
            UltiPro.Pages.AddChgLocations.Set(page => page.PhyicalAddressLine1Texbox, addLine1);
            UltiPro.Pages.AddChgLocations.Set(page => page.PhyicalAddressLine2Texbox, "APT. 326"); //optional
            UltiPro.Pages.AddChgLocations.Set(page => page.PhyicalAddressCityTexbox, city);
            UltiPro.Pages.AddChgLocations.Set(page => page.PhyicalAddressStateProvinceDropdown, province, SelectOption.Text);
            UltiPro.Pages.AddChgLocations.Set(page => page.PhyicalAddressZipPostalCodeTexbox, zipPostalCode);
        }
        
        public void AddANewCanadaLocation()
        {
            #region Login as System Admin MerrillG for Web Payroll Company
            UltiPro.Pages.Login.LoginAs("merrillg", "password", LanguageCode.EnUs);
            UltiPro.Pages.CompanySelector.ChooseCompanies("CALEN", "C0014");
            #endregion

            #region Navigate to System Admin | Business Rules | Locations
            UltiPro.Macros.Navigate.ToBusinessRule("Locations");
            #endregion

            #region Click on the Add button for a new location
            UltiPro.Pages.LocationSummary.ButtonBar.Click(button => button.Add);
            #endregion

            #region Select Canada as the Location country from the dropdown
            UltiPro.Pages.AddChgLocations.Set(page => page.LocationCountryDropdown, "Canada", SelectOption.Text);
            UltiPro.Pages.AddChgLocations.Is(page => page.LocationCountryDropdown, "innerHTML", "Canada");
            #endregion
        }
        #endregion
    }
}
